package com.kgis.kp.dao;

import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.SqlMapClientCallback;
import org.springframework.orm.ibatis.SqlMapClientTemplate;

import com.kgis.kp.common.vo.Ordering;
import com.kgis.kp.common.vo.Pagination;

/**
 * 
 * @author zhxiaomiao
 * 
 */
public interface IbatisDataAccessObject extends AbstractDataAccessObject {

	SqlMapClientTemplate getSqlMapClientTemplate();

	long sequence(String namespace);

	/** execute */
	<T> T execute(SqlMapClientCallback<T> sqlMapClientCallback);

	/** create */
	<T> T create(final String namespace, final T model);

	<T> int create(final String namespace, final List<T> models);

	/** retrieve/read/find */
	<T> T findById(final String namespace, long id);

	<T> T findOne(final String namespace, final String statement, final Object parameter);

	<T> T findOne(final String namespace, final String statement, final Map<String, Object> parameters);

	// <T> List<T> find(final String fullName, final CriteriaParameter
	// criteriaParameter, final Ordering ordering);

	<T> List<T> find(final String fullName, final Map<String, Object> parameters, final Ordering ordering);

	<T> List<T> find(final String fullName, final Map<String, Object> parameters);

	// <T> List<T> find(final String namespace, final String statement, final
	// CriteriaParameter criteriaParameter, final
	// Ordering ordering);

	<T> List<T> find(final String namespace, final String statement, final Map<String, Object> parameters, final Ordering ordering);

	<T> List<T> find(final String namespace, final String statement, final Map<String, Object> parameters);

	// sometimes need to find jdbc raw map
	// using jdbcTemplateDataAccessObject instead
	// List findRawMap(final String namespace, final String statement, final
	// Map<String, Object> parameters, final Ordering ordering);

	<T> Pagination<T> findPagination(final String fullName, final Map<String, Object> parameters, final Ordering ordering, final Pagination<T> pagination);

	<T> Pagination<T> findPagination(final String namespace, final String statement, final Map<String, Object> parameters, final Ordering ordering, final Pagination<T> pagination);

	<T> List<T> findAll(final String namespace);

	<T> List<T> findAll(final String namespace, final Ordering ordering);

	/** count */
	int count(final String fullName, final Map<String, Object> parameters);

	int count(final String namespace, final String statement, final Map<String, Object> parameters);

	/** also see <POJOs in Action> */
	/** update */
	<T> T update(final String namespace, final T model, final boolean optimisticLockStep);

	<T> T update(final String namespace, final T model);

	<T> int update(final String namespace, final List<T> models);

	int update(final String namespace, final String statement, final Object parameter);

	/** remove */
	<T> T remove(final String namespace, final T model);

	int remove(final String namespace, final String statement, final Object parameter);

	<T> int remove(final String namespace, final List<T> models);

}
